#@laybase() 
#define main()

<style>

.col-md-12 {
	position: relative;
	min-height: 100px;
}

.control {
	width: 80%;
    position: absolute;
    top: 10px;
    left: 15px;
}

.control select {
	display: inline-block;
    width: 16%;
}

.control input {
	display: inline-block;
    width: 12%;
}

.control button {
	margin-top: -5px;
}

#fuiouSignModal .modal-body .getsign {
	width: 132px;
    margin: 0 auto;
    display: block;
}

#fuiouSignModal .modal-body .signmsg .radiobox {
	margin: 15px 0;
}

#fuiouSignModal .modal-body .signmsg .errbox {
	display: none;
}

#fuiouSignModal .modal-body .signmsg .radiobox a {
	display: inline-block;
	margin-right: 15px;
    width: 90px;
    text-align: center;
    height: 36px;
    line-height: 34px;
    border: 1px solid #ddd;
    color: #666;
    text-decoration: none;
}

#fuiouSignModal .modal-body .signmsg .radiobox a i {
	padding-right: 3px;
}

#fuiouSignModal .modal-body .signmsg .radiobox a i.success {
	font-size: 15px;
	color: #0c3;
}

#fuiouSignModal .modal-body .signmsg .radiobox a i.error {
	font-size: 12px;
	color: #d9534f;
}

#fuiouSignModal .modal-body .signmsg .radiobox a.active {
	border-color: #337ab7;
	color: #337ab7;
}

#fuiouSignModal .modal-body .signmsg .radiobox a:hover {
	text-decoration: none;
}

#fuiouSignModal .modal-body .signmsg .errbox label {
	font-weight: normal;
	vertical-align: top;
}

#fuiouSignModal .modal-body .signmsg .errbox label {
	font-weight: normal;
	vertical-align: top;
}

#fuiouSignModal .modal-body .signmsg .errbox .form-control {
	display: inline-block;
	width: 56%;
}

.datatable a {
	white-space: nowrap;
}

#alert_confirm .modal-body {
	padding: 0;
	font-size: 14px;
	text-align: left;
	padding: 5px;
	overflow: auto;
}

#alert_confirm .modal-body div {
	line-height: 32px;
}

.fixed-table-container tbody tr:first-child td {
	white-space: nowrap;
}

#alert_confirm div.tab {
	margin: 20px 0;
	line-height: 20px;
}

#alert_confirm .modal-body span {
	height: 34px;
    padding: 7px 24px;
    font-size: 14px;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    display: inline-block;
    cursor: pointer;
    margin-right: 15px;
}

#alert_confirm .modal-body span.active {
	color: #1b82da;
	border-color: #1b82da;
}

</style>
<div class="modal fade" id="fuiouSignModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">提示</h4>
      </div>
      <div class="modal-body">
      	         
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary confirm" data-loading-text="请稍后...">提交</button>
      </div>
    </div>
  </div>
</div>

<div class="col-md-12" id="app">
	<div class="control">
		#@searchTab("opt",["苏宁","绿城"],["苏宁","绿城"])
		
		#@searchTab("state",["未代扣","代扣失败","代扣成功"],[-1,0,1])
		
	</div>
	<table class="datatable" id="datatable" data-unique-id="id"></table>
</div>

<script>
	$(function(){
		var $actIdx = "#(actIdx)",
			$table = $('#datatable'),
			searchDom = $("#searchbtn"),
			modalDom = $("#fuiouSignModal"),
			modalBody = modalDom.find(".modal-body"),
			modalTitle = modalDom.find(".modal-title"),
			modalConfirm = modalDom.find(".confirm"),
			signForm = $("#fuiouSignForm"),
			$allData = null
			
		axios.get("/fuioudq/fianceInfo")
		.then(function(res){
			console.log(res.data)
			var data = res.data,
				$data = data.data,
				titles = [{checkbox:true}],
				linkUrl = "cwfuioudqinfo"
			
			if($actIdx == 2){
				linkUrl = "csfuioudqinfo"
			}
			
			for(var i = 0;i < $data.length;i++){
				$data[i].id = i
				var html = "<a href='/fuioudq/"+ linkUrl +"/"+ $data[i].order_id +"' class='btn btn-primary' target='_blank'>代扣明细</a>&nbsp;<a href='/admin/dataDetails/"+ $data[i].order_id +"' class='btn btn-primary' target='_blank'>资料包</a>"
				if ($actIdx == 2) {
					var staus = null
					if ($data[i].staus === "还款中") {
						staus = 0
					} else if ($data[i].staus === "已处理") {
						staus = 1
					} else if ($data[i].staus === "已结清") {
						staus = 2
					} else if ($data[i].staus === "坏账") {
						staus = 3
					}
					html += "&nbsp;<a href='javascript:;' class='btn btn-primary changestaus-hook' data-oid='"+ $data[i].order_id +"' data-staus='"+ staus +"' class='btn btn-primary'>更新状态</a>"
				}
				$data[i].look_info = html
			}
			
			for(var i = 0;i < data.names.length;i++){
				titles.push({
					field: data.fields[i],
					title: data.names[i]
				})
			}
			
			titles.push({
				field: "look_info",
				title: "操作"
			})
			
			$allData = $data
			
			createTable(titles,$data)
		})
		
		//创建表格
		function createTable(titles,data){
			$table.bootstrapTable({
				uniqueId: 'id',	
				search: true,
				pagination: true, 
	            pageSize: 10,
			    columns: titles,
			    data: data,
			    clickToSelect: true,
			    showExport: true,
				exportTypes: ["excel"],
				exportOptions:{
					ignoreColumn:[0,11,12]
				}
			});		
		}
		
		$table.on("click","input[name='btSelectAll']",function(){
			var data = $table.bootstrapTable('getData'),
				isCheck = $(this).prop("checked")
			for(var i = 0;i < data.length;i++){
				data[i]["0"] = isCheck
			}
		})
	
		//搜索
		var searchtabDom = $(".searchtab-wrapper")
		searchtabDom.children("span").on("click",function(){
			var data = {}
			searchtabDom.each(function(){
				var input = $(this).children("input"),
					key = input.attr("key"),
					val = input.val()
				data[key] = val
			})

			axios.post("/fuioudq/fianceInfo",_x.qsStringify(data))
			.then(function(res){
				console.log(res.data)
				var nowData = res.data.data,
					linkUrl = "cwfuioudqinfo"
					
				if($actIdx == 2){
					linkUrl = "csfuioudqinfo"
				}
				for(var i = 0;i < nowData.length;i++){
					nowData[i].id = i
					var html = "<a href='/fuioudq/"+ linkUrl +"/"+ nowData[i].order_id +"' class='btn btn-primary' target='_blank'>代扣明细</a>&nbsp;<a href='/admin/dataDetails/"+ nowData[i].order_id +"' class='btn btn-primary' target='_blank'>资料包</a>"
					if ($actIdx == 2) {
						console.log(456)
						var staus = null
						if (nowData[i].staus === "还款中") {
							staus = 0
						} else if (nowData[i].staus === "已处理") {
							staus = 1
						} else if (nowData[i].staus === "已结清") {
							staus = 2
						} else if (nowData[i].staus === "坏账") {
							staus = 3
						}
						html += "&nbsp;<a href='javascript:;' class='btn btn-primary changestaus-hook' data-oid='"+ nowData[i].order_id +"' data-staus='"+ staus +"' class='btn btn-primary'>更新状态</a>"
					}
					nowData[i].look_info = html
				}
				$table.bootstrapTable("load",nowData)
			})
		})	
		
		$table.on("click","a.changestaus-hook",function(){
			var that = $(this),
				oid = that.data("oid"),
				option = {
					isShowBg: false,
					text: "<div class='tab'><input type='hidden' class='status-hook' value='' /><span data-staus='0'>还款中</span><span data-staus='1'>已处理</span><span data-staus='2'>已结清</span><span data-staus='3'>坏账</span></div>",
					fn: function(modalDom,btn,callback){
						var val = modalDom.find('.status-hook').val()
						if(_x.isEmpty(val)){
							_x.show_alert_sh("请选择状态",false)
							btn.button('reset')
							return
						}
						
						axios.post("/fuioudq/celPayStatusChange",_x.qsStringify({orderId: oid, status: val}))
						.then(function(res){
							if(res.data.code == 1){
								_x.show_alert_sh(res.data.msg,true)
								callback()
							}else{
								_x.show_alert_sh(res.data.msg,false)
								btn.button('reset')
							}
						})
						.catch(function(){
							_x.show_alert_sh("更新失败！",false)
							btn.button('reset')
						})
					}
				}
			_x.show_alert_confirm(option)
		})
		
		$("#alert_confirm").on("click", ".tab span",function(){
			var val = $(this).data("staus")
			$(this).siblings(".status-hook").val(val)
			$(this).addClass("active").siblings().removeClass("active")
		})
	})
</script>
#end